package com.sxkiler.demo.web.config;//package com.sxkiler.demo.configuration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DynamicDataSourceHolder {
    private final static Logger logger = LoggerFactory.getLogger(DynamicDataSourceHolder.class);
    public static final String DATA_SOURCE_WRITE = "master";
    public static final String DATA_SOURCE_READ = "slave";

    public static final ThreadLocal<String> holder = new ThreadLocal<String>();

    public static void putDataSource(String name) {
        holder.set(name);
    }

    public static String getDataSource() {
        logger.debug("data_source_type:{}",holder.get());
        if(holder.get()==null){
            return "master";
        }else{
            return holder.get();
        }
    }
}
